﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TiposComuns.Objectos;
using Servidor.Objectos;
using Servidor.Objectos.Pesquisa;

namespace Servidor.WebServices
{
    public class Peer : MarshalByRefObject, IPeer
    {
        //private Proxy proxy;
        #region IPeer Members

        #region Meta
        public Peer(){ }

        public void SetView(View view)
        {
            Proxy.GetInstance().SetView(view);
        }

        public void RollBack(IDMsg id)
        {
            Proxy.GetInstance().RollBack(id);
        }

        public override object InitializeLifetimeService()
        {
            return null;
        }

        /// <summary>
        /// Gets the state of the server
        /// </summary>
        /// <param name="id of the requester server"></param>
        /// <param name="state of the requester server"></param>
        /// <returns>The current state of the server</returns>
        public Synchronization CheckView(TiposComuns.Objectos.State state, int id)
        {
            return Proxy.GetInstance().CheckView(state,id);
        }

        public void Synchronize(List<Servidor.Objectos.Action> actions)
        {
            throw new NotImplementedException();
        }

        public List<Servidor.Objectos.Action> GetActionsSince(IDMsg idMsg)
        {
            return Proxy.GetInstance().GetActionsSince(idMsg);
        }
        

        public State GetState()
        {
            return Proxy.GetInstance().GetState();
        }

        public Synchronization Update(int serv,Synchronization sync)
        {
            return Proxy.GetInstance().Update(serv,sync);
        }

        public void SetState(State state)
        {
            Proxy.GetInstance().SetState(state);
        }

        public void ServerExit(int id)
        {
            Proxy.GetInstance().ExitServer(id);
        }

        public void RemovePendents(List<int> pends)
        {
            Proxy.GetInstance().RemoveLocalPendents(pends);
        }

        public bool isAlive()
        {
            return Proxy.GetInstance().isAlive();
        }
        #endregion

        #region Profile
        public Profile GetProfile()
        {
            return Proxy.GetInstance().GetProfile();
        }
        #endregion

        #region Posts

        public List<Post> PostsSince(string user,int last)
        {
            return Proxy.GetInstance().PostsSince(user,last);
        }

        #endregion

        #region Friends
        public bool FriendReceive(Person sender)
        {
            return Proxy.GetInstance().FriendReceive(sender);
        }

        public bool BeAccepted(Person sender)
        {
            return Proxy.GetInstance().BeAccepted(sender);
        }

        public bool BeRejected(Person sender)
        {
            return Proxy.GetInstance().BeRejected(sender);
        }

        public bool BeRemoved(Person sender)
        {
            return Proxy.GetInstance().BeRemoved(sender);
        }

        #endregion

        #region Search
        public void SetTree(KTree tree)
        {
            Proxy.GetInstance().SetTree(tree);
        }

        public KClosest GetClosest(byte []hash)
        {
            int i = 0;
            return Proxy.GetInstance().GetLocalKClosest(hash);
        }

       
        public SearchResult GetSearched(byte[] key)
        {
            return Proxy.GetInstance().GetSearched(key);
        }



        public KeyValuePair<SearchResult, bool> StoreSearched(byte[] key, Person person)
        {
            return Proxy.GetInstance().StoreSearched(key, person);
        }

        public SearchResult Store(byte[] key, SearchResult res)
        {
            return Proxy.GetInstance().Store(key, res);
        }

        public KeyValuePair<SearchResult, bool> RemoveSearched(byte[] key, Person person)
        {
            return Proxy.GetInstance().RemoveSearched(key,person);
        }

        public bool HashSearched(byte []key)
        {
            return Proxy.GetInstance().HasSearched(key);
        }

        #endregion       
        
        #endregion

        
    }
}
